#include <stdio.h>
#include "jsmf.h"

#define JSMF_TOK_BUF_SIZE 64
#define RST_BUF_LEN 512
static jsmftok_t jsmf_tok_buf[JSMF_TOK_BUF_SIZE];

static char rst[RST_BUF_LEN] = {0};

void test_string()
{
    jsmf_obj root = JsmfInitRoot(jsmf_tok_buf, JSMF_TOK_BUF_SIZE);
    AddStringToObject(root, "welcome", "hello jsmf");
    PrintJsonStr(root, rst, RST_BUF_LEN);
}

void test_int()
{
    jsmf_obj root = JsmfInitRoot(jsmf_tok_buf, JSMF_TOK_BUF_SIZE);
    AddNumToObject(root, "num", 123);
    PrintJsonStr(root, rst, RST_BUF_LEN);
}

void test_obj()
{
    jsmf_obj root = JsmfInitRoot(jsmf_tok_buf, JSMF_TOK_BUF_SIZE);
    jsmf_obj school = AddObjToObject(root, "school");
    AddStringToObject(school, "name", "xdu");
    AddNumToObject(school, "founders year", 123);
    PrintJsonStr(root, rst, RST_BUF_LEN);
}

void test_array()
{
    jsmf_obj root = JsmfInitRoot(jsmf_tok_buf, JSMF_TOK_BUF_SIZE);
    jsmf_obj school = AddObjToObject(root, "school");
    jsmf_obj course = AddArrToObject(school, "name");
    AddStringToArray(course, "software");
    AddStringToArray(course, "communication");
    PrintJsonStr(root, rst, RST_BUF_LEN);
}

int main()
{
    test_string();
    printf("%s\n",rst);

    test_int();
    printf("%s\n",rst);

    test_obj();
    printf("%s\n",rst);

    test_array();
    printf("%s\n",rst);
}
